package mess;

import java.time.chrono.MinguoChronology;

public class LeeCode_2383 {
    public static void main(String[] args) {
        System.out.println(minNumberOfHours(5, 3, new int[]{1, 4, 3, 2}, new int[]{2, 6, 3, 1}));
        System.out.println(minNumberOfHours(2, 4, new int[]{1}, new int[]{3}));
    }
    private static int minNumberOfHours(int initialEnergy, int initialExperience, int[] energy, int[] experience) {
        int res = 0;
        int len = energy.length;
        for (int i = 0; i < energy.length; i++) {
            if (initialEnergy <= energy[i]){
                int need = energy[i] - initialEnergy + 1;
                res += need;
                initialEnergy += need;
            }
            initialEnergy -= energy[i];
        }
        for (int i = 0; i < experience.length; i++) {
            if (initialExperience <= experience[i]){
                int need = experience[i] - initialExperience + 1;
                res += need;
                initialExperience += need;
            }
            initialExperience += experience[i];
        }
        return res;
    }
}
